package models

import (
	"time"
)

// FinancialStats 财务统计数据模型
type FinancialStats struct {
	ID               uint      `gorm:"primaryKey" json:"id"`
	Date             string    `gorm:"size:20;not null;index" json:"date"`
	Income           float64   `gorm:"not null" json:"income"`
	Expense          float64   `gorm:"not null" json:"expense"`
	NetIncome        float64   `gorm:"not null" json:"net_income"`
	TransactionCount int       `gorm:"not null" json:"transaction_count"`
	CreatedAt        time.Time `json:"created_at"`
	UpdatedAt        time.Time `json:"updated_at"`
}

// TableName 指定表名
func (FinancialStats) TableName() string {
	return "financial_stats"
}

// FinancialSummary 财务汇总信息模型
type FinancialSummary struct {
	ID                uint      `gorm:"primaryKey" json:"id"`
	StartDate         string    `gorm:"size:20;not null" json:"start_date"`
	EndDate           string    `gorm:"size:20;not null" json:"end_date"`
	TotalIncome       float64   `gorm:"not null" json:"total_income"` // 收入
	TotalExpense      float64   `gorm:"not null" json:"total_expense"`
	NetIncome         float64   `gorm:"not null" json:"net_income"`
	IncomeChangeRate  float64   `gorm:"not null" json:"income_change_rate"`
	ExpenseChangeRate float64   `gorm:"not null" json:"expense_change_rate"`
	NetChangeRate     float64   `gorm:"not null" json:"net_change_rate"`
	TotalTransactions int       `gorm:"not null" json:"total_transactions"`
	CreatedAt         time.Time `json:"created_at"`
	UpdatedAt         time.Time `json:"updated_at"`
}

// TableName 指定表名
func (FinancialSummary) TableName() string {
	return "financial_summary"
}

// TransactionItem 交易明细模型
type TransactionItem struct {
	ID              uint      `gorm:"primaryKey" json:"id"`
	TransactionID   string    `gorm:"size:50;not null;uniqueIndex" json:"transaction_id"`
	TransactionTime string    `gorm:"size:50;not null;index" json:"transaction_time"`
	TransactionType string    `gorm:"size:20;not null;index" json:"transaction_type"` // income, expense
	Description     string    `gorm:"size:255;not null" json:"description"`
	Amount          float64   `gorm:"not null" json:"amount"`
	PaymentMethod   string    `gorm:"size:50" json:"payment_method"`
	Status          string    `gorm:"size:20;not null" json:"status"` // success, pending, failed, refunded
	CreatedAt       time.Time `json:"created_at"`
	UpdatedAt       time.Time `json:"updated_at"`
}

// TableName 指定表名
func (TransactionItem) TableName() string {
	return "transactions"
}

// IncomeBreakdownItem 收入明细项目模型
type IncomeBreakdownItem struct {
	ID         uint      `gorm:"primaryKey" json:"id"`
	Category   string    `gorm:"size:100;not null" json:"category"`
	Amount     float64   `gorm:"not null" json:"amount"`
	Percentage float64   `gorm:"not null" json:"percentage"`
	DateRange  string    `gorm:"size:100;not null" json:"date_range"`
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
}

// TableName 指定表名
func (IncomeBreakdownItem) TableName() string {
	return "income_breakdown"
}

// ExpenseBreakdownItem 支出明细项目模型
type ExpenseBreakdownItem struct {
	ID         uint      `gorm:"primaryKey" json:"id"`
	Category   string    `gorm:"size:100;not null" json:"category"`
	Amount     float64   `gorm:"not null" json:"amount"`
	Percentage float64   `gorm:"not null" json:"percentage"`
	DateRange  string    `gorm:"size:100;not null" json:"date_range"`
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
}

// TableName 指定表名
func (ExpenseBreakdownItem) TableName() string {
	return "expense_breakdown"
}
